<template>
  <div>
    <!-- <h3>
        路由传参 --  query传参 （url可见）
      </h3> -->

    <div>
      <!-- 编程式传参 -->
      <!-- <h3 v-for="item in list" @click="goDetail(item.id, item.title)" :key="item.id">
        {{ item.title }}
      </h3> -->

      <!-- 声明式传参 -->
      <router-link v-for="item in list"
                   tag="h4"
                   :to="{ 
                     path: '/detail',
                     query: {
                       id: item.id
                     }
                    }" :key="item.id">
        {{ item.title }}
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [
        {
          id: 111,
          title: "商品1",
        },
        {
          id: 222,
          title: "商品2",
        },
        {
          id: 333,
          title: "商品3",
        },
      ],
    };
  },
  created() {
    // console.log(this.$route)
  },
  methods: {
    goDetail(id, title) {
      // 路由传参两种方式
      // 1. query (url中可见)
      this.$router.push({
        // path: url
        path: "/detail",
        // 设置参数
        query: {
          id,
          // title
        }
      });
    },
  },
};
</script>

<style scoped>
h3 {
  height: 80px;
}
</style>